#ifndef TOUCH_HPP
#define TOUCH_HPP


#include <Arduino.h>
#include <lvgl.h>
#include "drivers/CST820.h"

#define I2C_SDA 21
#define I2C_SCL 22

CST820 touch(I2C_SDA, I2C_SCL, -1, -1); /* 触摸实例 */
lv_indev_t *myInputDevice;

void my_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
{

    bool touched;
    uint8_t gesture;
    uint16_t touchX, touchY;

    touched = touch.getTouch(&touchX, &touchY, &gesture);

    if (!touched)
    {
        data->state = LV_INDEV_STATE_REL;
    }
    else
    {
        data->state = LV_INDEV_STATE_PR;

        /*Set the coordinates*/
        data->point.x = touchX;
        data->point.y = touchY;
        // Serial.printf("Touch coordinates: %d, %d\n", touchX, touchY);

    }
}

void touchInit(){
    touch.begin(); /*初始化触摸板*/
    vTaskDelay(10);
    static lv_indev_drv_t indev_drv;
    lv_indev_drv_init(&indev_drv);
    indev_drv.type = LV_INDEV_TYPE_POINTER;
    indev_drv.read_cb = my_touchpad_read;
    lv_indev_drv_register(&indev_drv);
}




#endif